package com.zhongxi.guoyuan.adapter.coinShop;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.coinStore.PostRewardCoinDetailData;
import com.zhongxi.guoyuan.url.Url;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

import static com.zhongxi.guoyuan.R.id.tv_reward_coin;
import static com.zhongxi.guoyuan.R.id.tv_reward_price;

/**
 * Created by Administrator on 2017/6/23.
 */

public class SameRewardGoodAdapter extends BaseAdapter {

    private Context context;
    private List<PostRewardCoinDetailData> datas;

    public SameRewardGoodAdapter(Context context, List<PostRewardCoinDetailData> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int i) {
        return datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder vh;
        if (view == null) {
            view = View.inflate(context, R.layout.item_reward_coin, null);
            vh = new ViewHolder(view);
            view.setTag(vh);
        } else {
            vh = (ViewHolder) view.getTag();
        }
        PostRewardCoinDetailData rewardCoinDetailData = datas.get(i);
        Glide.with(context).load(Url.IMG_URL + rewardCoinDetailData.getThumbnail()).placeholder(R.mipmap.iv_eg).fitCenter().into(vh.ivImg);
        if (null != rewardCoinDetailData.getName() && !"".equals(rewardCoinDetailData.getName())) {
            vh.tvName.setText(rewardCoinDetailData.getName());
        } else {
            vh.tvName.setText("");
        }
        if(null!=rewardCoinDetailData.getOrdernum()&&!"".equals(rewardCoinDetailData.getOrdernum())){
            vh.tvView.setText("销量: "+rewardCoinDetailData.getOrdernum());
        }else{
            vh.tvView.setText("销量: 0");
        }
        if (rewardCoinDetailData.getFloorprice().equals(rewardCoinDetailData.getPeakprice())) {
            vh.tvRewardPrice.setText(rewardCoinDetailData.getFloorprice() + "元");
        } else {
           // vh.tvRewardPrice.setText(rewardCoinDetailData.getFloorprice() + "元 ~ " + rewardCoinDetailData.getPeakprice() + "元");
            vh.tvRewardPrice.setText(rewardCoinDetailData.getFloorprice() + "元");
        }

        switch (rewardCoinDetailData.getGoodstype()) {
            case 1:
                if (rewardCoinDetailData.getFloorprice().equals(rewardCoinDetailData.getPeakprice())) {
                    vh.tvRewardCoin.setText("立即赠 " + rewardCoinDetailData.getFloorprice() + " 美豆");
                } else {
                    //vh.tvRewardCoin.setText("立即赠" + rewardCoinDetailData.getFloorprice() + "美豆 ~ " + rewardCoinDetailData.getPeakprice() + "美豆");
                    vh.tvRewardCoin.setText("立即赠" + rewardCoinDetailData.getFloorprice() + "美豆");
                }
                break;
//                case 2:
//                    if (goodsInfos.getFloorprice().equals(goodsInfos.getPeakprice())) {
//                        tv_reward_coin.setText("立即赠 " + DataUtil.multiplys(goodsInfos.getFloorprice(), "2") + " 美豆");
//                    } else {
//                        tv_reward_coin.setText("立即赠" + DataUtil.multiplys(goodsInfos.getFloorprice(), "2") + "美豆 ~ " + DataUtil.multiplys(goodsInfos.getPeakprice(), "2") + "美豆");
//                    }
//                    break;
            case 3:
                if (rewardCoinDetailData.getFloorprice().equals(rewardCoinDetailData.getPeakprice())) {
                    vh.tvRewardCoin.setText("分期奖 " + rewardCoinDetailData.getFloorprice() + " 红豆");
//                        tv_reward_yield.setText("分期奖 " + goodsInfos.getFloorprice() + " 红豆");
                } else {
//                    vh.tvRewardCoin.setText("分期奖" + rewardCoinDetailData.getFloorprice() + "红豆 ~ " + rewardCoinDetailData.getPeakprice() + "红豆");
                    vh.tvRewardCoin.setText("分期奖" + rewardCoinDetailData.getFloorprice() + "红豆");
//                        tv_reward_yield.setText("分期奖" + goodsInfos.getFloorprice() + "红豆 ~ " + goodsInfos.getPeakprice() + "红豆");
                }
                break;
        }
        return view;
    }

    static class ViewHolder {
        @Bind(R.id.ivImg)
        ImageView ivImg;
        @Bind(R.id.tvName)
        TextView tvName;
        @Bind(R.id.tvView)
        TextView tvView;
        @Bind(tv_reward_price)
        TextView tvRewardPrice;
        @Bind(R.id.tv_reward_yield)
        TextView tvRewardYield;
        @Bind(tv_reward_coin)
        TextView tvRewardCoin;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
